package com.example.a1.layouttext322jzy;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener
        ,View.OnClickListener
        ,CompoundButton.OnCheckedChangeListener{

    private TextView textView;
    private EditText editText;
    private Button getEdit;
    private ImageView imageView;
    private Button changeImage;
    private ImageButton imageButton;
    private RadioGroup radioGroup;
    private RadioButton boy,girl;
    private Button getSex;
    private CheckBox lan,zhu,pai;
    private Button getHobi;
    private String xinqu="";
    boolean flag1 = true;
    boolean flag2 = true;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();

    }



    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {

        switch (checkedId){
            case R.id.radioButton://女
                textView.setText("女");
                break;
            case R.id.radioButton2://男
                textView.setText("男");
                break;

        }
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.button:
                textView.setText(editText.getText().toString());
                break;
            case R.id.button4:

                if (flag1){
                    textView.setText("图片更换为jzy322");
                    imageView.setImageResource(R.drawable.jzy322);
                    flag1 = false;
                }else {
                    textView.setText("图片更换为系统图标");
                    imageView.setImageResource(R.mipmap.ic_launcher);
                    flag1 =true;
                }

                break;
            case R.id.imageButton2:

                if (flag2){
                    textView.setText("图片更换为lzw_123");
                    imageButton.setImageResource(R.drawable.jzy322);
                    flag2 = false;
                }else {
                    textView.setText("图片更换为系统图标");
                    imageButton.setImageResource(R.mipmap.ic_launcher);
                    flag2 =true;
                }
        }
    }



    public void init(){
        //获取控件
        textView = (TextView) findViewById(R.id.textView4);
        editText = (EditText) findViewById(R.id.editText);
        getEdit = (Button) findViewById(R.id.button);
        imageView = (ImageView) findViewById(R.id.imageView);
        changeImage = (Button) findViewById(R.id.button4);
        imageButton = (ImageButton) findViewById(R.id.imageButton2);
        radioGroup = (RadioGroup) findViewById(R.id.radio_group);
        boy = (RadioButton) findViewById(R.id.radioButton);
        girl = (RadioButton) findViewById(R.id.radioButton2);
        lan = (CheckBox) findViewById(R.id.checkBox3);
        zhu = (CheckBox) findViewById(R.id.checkBox2);
        pai = (CheckBox) findViewById(R.id.checkBox);


        //注册监听
        getEdit.setOnClickListener(this);
        changeImage.setOnClickListener(this);
        imageButton.setOnClickListener(this);
        radioGroup.setOnCheckedChangeListener(this);
        lan.setOnCheckedChangeListener(this);
        zhu.setOnCheckedChangeListener(this);
        pai.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        switch (buttonView.getId()){
            case R.id.checkBox3://篮球
                if (isChecked){
                    xinqu += "篮球+";
                }else {
                    xinqu = xinqu.replace("篮球+","");
                }
                textView.setText(xinqu);
                break;
            case R.id.checkBox2://足球
                if (isChecked){
                    xinqu += "足球+";
                }else {
                    xinqu = xinqu.replace("足球+","");
                }
                textView.setText(xinqu);
                break;
            case R.id.checkBox://排球
                if (isChecked){
                    xinqu += "排球+";
                }else {
                    xinqu = xinqu.replace("排球+","");
                }
                textView.setText(xinqu);
                break;
        }
    }
    }

